package com.fenghongzhang.day008;

import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.uuzuche.lib_zxing.activity.CodeUtils;

public class Main2Activity extends AppCompatActivity {

    private Button btn;
    private Button btn1;
    private ImageView img;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);


        btn = (Button) findViewById(R.id.btn);
        btn1 = (Button) findViewById(R.id.btn1);
        img = (ImageView) findViewById(R.id.img);
        TestManager.getInstance().add(this);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            requestPermissions(new String[]{Manifest.permission.CAMERA,Manifest.permission.VIBRATE,Manifest.permission.WRITE_EXTERNAL_STORAGE}, 200);
        }

    }

    public void btn(View view) {
        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
        Bitmap code = CodeUtils.createImage("安卓3哈哈哈", 400, 400, bitmap);
        img.setImageBitmap(code);
    }

    public void btn1(View view) {
//        Intent intent = new Intent(this, CaptureActivity.class);
//        startActivityForResult(intent,101);
        Intent intent = new Intent(this,Main3Activity.class);
        startActivity(intent);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode == 101 && resultCode == Activity.RESULT_OK &&data != null){
            Bundle bundle = data.getExtras();
            if(bundle == null){
                return;
            }
            if(bundle.getInt(CodeUtils.RESULT_TYPE) == CodeUtils.RESULT_SUCCESS){
                String string = bundle.getString(CodeUtils.RESULT_STRING);
                Toast.makeText(this, "扫描结果"+string, Toast.LENGTH_SHORT).show();
            }
        }
    }
}
